import { asyncRoutes, constantRoutes } from '@/router'

const state = {
  routes: constantRoutes || []
}
const mutations = {
  setRoutes(state, otherRoute) {
    state.routes = [
      ...constantRoutes,
      ...otherRoute
    ]
  }
}
const actions = {
  filterRoute(context, menus) {
    const otherRoute = asyncRoutes.filter(item => {
      if (menus.includes(item.children[0].name)) {
        return true
      } else {
        return false
      }
    })
    context.commit('setRoutes', otherRoute)
    return otherRoute
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
